<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
		<link rel="stylesheet" href="css/bootstrap.css" />
		<link rel="stylesheet" href="css/publish_article.css" />
		<script src="node_modules/axios/dist/axios.js"></script>
		<script src="js/register.js"></script>
	</head>
	<body>
		<div class="container col-sm-12">
			<form role="form" class="col-sm-8 article_form" id="add_claafily">
				<div class="form-group">
					<label for="name" class="col-sm-12 title_lab">添加分类</label>
					<div class="col-sm-6 title_inp">
						<input
							type="text"
							class="form-control"
							id="article_title"
							placeholder="请输入分类名称"
						/>
					</div>
				</div>
				<button type="submit" class="btn btn-success">添加</button>
			</form>
			<div class="classifly_list">
				<strong>分类列表</strong>
				<ul class="list-group"></ul>
			</div>
		</div>
		<div id="myAlert" class="alert alert-success col-sm-4 col-sm-offset-3">
			<a href="#" class="close" data-dismiss="alert">&times;</a>
			<strong>文章发布成功!!!</strong>
		</div>
	</body>
	<script>
		axios.defaults.headers.common["SAT"] = "1234567";
		let admin = new Admin();
		//判断是否有权限
		admin.jurisdiction();

		admin.listOfCategories();
		//添加分类
		document.querySelector("#add_claafily").addEventListener("submit", (e) => {
			e.preventDefault();
			let formdata = new FormData();
			formdata.append("title", admin.getVal("#article_title"));
			axios
				.post("https://ty.php800.cn/api/article/classadd.php", formdata, {
					headers: {
						TOKEN: localStorage.getItem("token"),
					},
				})
				.then((result) => {
					let { verify, msg } = result.data;
					admin.popUpBox(verify, msg);
					admin.listOfCategories();
				})
				.catch((err) => console.log(err));
		});
		//获取分类列表

		document.querySelector(".list-group").addEventListener("click", (e) => {
			if (e.target.nodeName === "SPAN") {
				let span = e.target;
				axios
					.get("https://ty.php800.cn/api/article/classdel.php", {
						params: {
							id: span.parentNode.value,
						},
					})
					.then((result) => {
						console.log(result);
						let { verify, msg } = result.data;
						admin.popUpBox(verify, msg);
						admin.listOfCategories();
					})
					.catch((err) => console.log(err));
			}
		});
	</script>
</html>
